package com.example.yuejianapp14.Activity.Fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;

import com.example.yuejianapp14.Activity.Activity.SearchActivity;
import com.example.yuejianapp14.Activity.Adapter.ClubAdapter;
import com.example.yuejianapp14.Activity.JavaBean.Club;
import com.example.yuejianapp14.Activity.Listener.ClubListener;
import com.example.yuejianapp14.Activity.Model.ClubModel;
import com.example.yuejianapp14.R;

import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class ClubFragment extends Fragment {
    private RecyclerView recyclerView;
    private List mDataList;
    private View view;
    private ImageButton clubfind;

    public ClubFragment() {
        // Required empty public constructor
    }

ClubListener clubListener = new ClubListener() {
    @Override
    public void onResponse(List<Club> beanList) {
        mDataList=beanList;
        ClubAdapter adapter = new ClubAdapter(getActivity(),mDataList);
        recyclerView.setAdapter(adapter);
    }

    @Override
    public void onFail(String msg) {

    }
};

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view=inflater.inflate(R.layout.fragment_club, container, false);
        initRecyclerView();
        getData();
        return view;

    }
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        ImageButton clubfind = (ImageButton) getActivity().findViewById(R.id.clubfind);
        clubfind.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), SearchActivity.class);
                startActivity(intent);
            }
        });
    }


    private void getData() {
        ClubModel clubModel =new ClubModel();
        clubModel.getClubList(clubListener);
    }

    private void initRecyclerView() {
        recyclerView = (RecyclerView) view.findViewById(R.id.rv);
        recyclerView.setLayoutManager(new LinearLayoutManager((this.getActivity())));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
    }

}
